<?php

require_once 'StringKit/CEncoding.php';
require_once 'StringKit/COneBytePerCharString.php';
require_once 'StringKit/CBuiltInEncodings.php';

class CASCIIString extends COneBytePerCharString {
	function IteratorClass() {
		return 'CASCIIIterator';
	}
	
	function MakeNewFromBuffer($buffer, $skipCheck = null) {
		if (!$skipCheck) {
			$l = strlen($buffer);
			for ($i = 0; $i < $l; $i++) {
				if (ord($buffer[$i]) > 127)
					return null;
			}
		}
		
		return new CASCIIString($buffer);
	}
	
	function FastBufferOfEncoding($enc) {
		if ($enc == kASCII)
			return $this->Buffer;
		else
			return null;
	}
}

class CASCIIIterator extends COneBytePerCharIterator {
	function ByteToChar($x) {
		return ord($x);
	}
}

class CASCIIEncoder extends COneBytePerCharEncoder {
	function AppendString($x) {
		$this->FastAppendIfEncoding($x, kASCII) or
			parent::AppendString($x);
	}
	
	function BytesForChar($x) {
		if ($x > 127) return null;
		return chr($x);
	}
}

?>